#include "stdafx.h"
#include "PaintHelper.h"


PaintHelper::PaintHelper(void)
{
}

PaintHelper::PaintHelper(HDC mhdc){
	hdc=mhdc;
	initPosX=50;
	initPosY=50;
	currentPosX=initPosX;
	currentPosY=initPosY;
	SetBkMode(hdc, OPAQUE);
	hpen=CreatePen(PS_SOLID,4,RGB(0,255,0));
	SelectObject(hdc,hpen);
	MoveToEx(hdc,initPosX,initPosY,NULL);
	SetTextColor(hdc,RGB(255,0,0));
}

PaintHelper::~PaintHelper(void)
{
}

void PaintHelper::drawLine(int startX,int startY,int endX,int endY){
	MoveToEx(hdc,startX,startY,NULL);
	LineTo(hdc,endX,endY);
	setCurrentPos(endX,endY);
}
	void PaintHelper::drawLineOffset(int offX,int offY){
		LineTo(hdc,currentPosX+offX,currentPosY+offY);
		setCurrentPos(currentPosX+offX,currentPosY+offY);
	}
	void PaintHelper::drawText(char * str,int x,int y){
		TextOut(hdc,x,y,str,lstrlen(str));
	}
	void PaintHelper::drawTextOffset(char * str,int offx,int offy){
		TextOut(hdc,currentPosX+offx,currentPosY+offy,str,lstrlen(str));
	}
	int PaintHelper::getCurrentX(){
		return currentPosX;
	}
	int PaintHelper::getCurrentY(){
		return currentPosY;
	}

	void PaintHelper::setInitPos(int x,int y){
		initPosX=x;
		initPosY=y;
	}
	void PaintHelper::setCurrentPos(int x,int y){
		currentPosX=x;
		currentPosY=y;
	}
	
	PaintHelper &PaintHelper::operator=(const PaintHelper p){
		int currentPosX=p.currentPosX;
		int currentPosY=p.currentPosY;
		int initPosX=p.initPosX;
		int initPosY=p.initPosY;
		HDC hdc=p.hdc;
		HPEN hpen=p.hpen;
		HBRUSH hbrush=p.hbrush;
		return *this;
	}

	void PaintHelper::drawParalleLine(int startX,int startY,int endX,int endY,int height){
		moveTo(startX,startY);
		LineTo(hdc,endX,endY);
		moveTo(startX,startY+height);
		LineTo(hdc,endX,endY+height);
		moveTo(endX,endY);
	}
	void PaintHelper::drawParalleLineOffset(int offX,int offY,int height){
		int startX=currentPosX;
		int startY=currentPosY;
		int endX=currentPosX+offX;
		int endY=currentPosY+offY;
		moveTo(startX,startY);
		LineTo(hdc,endX,endY);
		moveTo(startX,startY+height);
		LineTo(hdc,endX,endY+height);
		moveTo(endX,endY);
	}

	void PaintHelper::moveTo(int x,int y){
		MoveToEx(hdc,x,y,NULL);
		currentPosX=x;
		currentPosY=y;
	}

	
void PaintHelper::drawVerticalLine(int x,int y,int height){
	int cx=currentPosX;
	int cy=currentPosY;
	drawLine(x,y,x,y+height);
	moveTo(cx,cy);
}
	void PaintHelper::drawVerticalLineOffset(int height){
	int cx=currentPosX;
	int cy=currentPosY;
	drawLineOffset(0,height);
	moveTo(cx,cy);
	}